﻿using System.Linq;
using System.Collections.Generic;
using System;

using Csla;

using Haushaltsbuch.DataAcces.Entities;

namespace Haushaltsbuch.Domain.Users
{
    [Serializable]
    public class RoleEdit : BusinessBase<RoleEdit>
    {
        private static readonly PropertyInfo<int> IdProperty =
            RegisterProperty<int>(o => o.Id);

        public int Id
        {
            get { return this.GetProperty(IdProperty); }
            set { this.SetProperty(IdProperty, value); }
        }

        private static readonly PropertyInfo<string> NameProperty =
            RegisterProperty<string>(o => o.Name);

        public string Name
        {
            get { return this.GetProperty(NameProperty); }
            set { this.SetProperty(NameProperty, value); }
        }

        private Role ToEntity()
        {
            return new Role()
                {
                    Id = this.ReadProperty(IdProperty),
                    Name = this.ReadProperty(NameProperty)
                };
        }

        internal static RoleEdit Get(Role entity)
        {
            return DataPortal.FetchChild<RoleEdit>(entity);
        }

        private void Child_Fetch(Role entity)
        {
            this.LoadProperty(IdProperty, entity.Id);
            this.LoadProperty(NameProperty, entity.Name);
        }
    }
}